//
//  main.m
//  LinearList
//
//  Created by H on 2017/7/26.
//  Copyright © 2017年 H. All rights reserved.
//  

#import <Foundation/Foundation.h>
#import "LinearList.h"
#import "NSArray+address.h"
#import "Person.h"

/*
 LLDB : Low Level Debugger
 
 可变数组的扩容:
 
 1.每次容量不够了,需要扩容就会malloc一块新的区域!!
 2.复制旧数据到新区域!!
 3.将旧空间free掉!!
  */
 
 /*
 汇编混编两种:
 1.内联汇编（asm（））  2.外链汇编
 */
 



void DemoP(){
    
    Person * p1 = [Person personWithName:@"P1"];
    Person * p2 = [Person personWithName:@"P2"];
    Person * p3 = [Person personWithName:@"P3"];
    
    //创建线性表
    LinearList * list = listCreat(10);
    //添加数据
    listAdd(list, (__bridge LinearListNodeValue)p1);
    listAdd(list, (__bridge LinearListNodeValue)p2);
    listAdd(list, (__bridge LinearListNodeValue)p3);
    
    //打印
    listPrint(list);
    //取出节点数据
    Person * p  = (__bridge Person *)(listGet(list, 1));
    [p run];
    //销毁
    listReleas(list);
    list = NULL;
}


void test1(){
    //创建
    LinearList * list = listCreat(5);
    //添加数据
    listAdd(list, (LinearListNodeValue)1);
    listAdd(list, (LinearListNodeValue)2);
    listAdd(list, (LinearListNodeValue)3);
    listAdd(list, (LinearListNodeValue)4);
    listAdd(list, (LinearListNodeValue)5);
    listRemove(list, 2);
    listAdd(list, (LinearListNodeValue)6);
    //1  2  4  5  6
    //打印
    listPrint(list);
    //销毁
    listReleas(list);
    list = NULL;
}

void testArr(){
    NSMutableArray * arr = [NSMutableArray arrayWithCapacity:0];
    NSLog(@"数组元素的首地址是:%p",arr.elementsAddress);
    for (int i = 0; i < 10; i++) {
        [arr addObject:@"11"];
        NSLog(@"长度是:%zd 地址:%p",arr.count,arr.elementsAddress);
    }
    NSLog(@"%zd",arr.count);
}

void DemoInt(){
    
    //返回一个结构体!
    LinearList * list = listCreat(5);
    //添加数据
    for (int i = 0; i < 20; i++) {
        listAdd(list, (LinearListNodeValue)i);
        NSLog(@"长度:%d,首元素地址:%p",listLength(list),*((void **)list + 1));
    }
    //打印数据
    listPrint(list);
    
    //销毁
    listReleas(list);
}

int sum(int a,int b);

int main(int argc, const char * argv[]) {
    @autoreleasepool {
         NSLog(@"%d",sum(10, 20));
        DemoInt();
        
    }
    return 0;
}
